package com.jandar.spider.schedule;

import com.jandar.spider.config.property.SpiderConfig;
import com.jandar.spider.enums.ContentBiddingProvinceEnum;
import com.jandar.spider.service.ContentBiddingStatisticsService;
import com.jandar.spider.task.ContentBiddingTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ContentBiddingSchedule {
    @Autowired
    private ContentBiddingTask contentBiddingTask;
    @Autowired
    private SpiderConfig spiderConfig;
    @Autowired
    private ContentBiddingStatisticsService contentBiddingStatisticsService;

    @Scheduled(cron = "${property.spider.cron}")
    public void exec() {
        if (spiderConfig.getSpider().getZtb().getZjDailyTask()) {
            start(ContentBiddingProvinceEnum.ZJ.getName(), "ZJ");
        }
        if (spiderConfig.getSpider().getZtb().getHbDailyTask()) {
            start(ContentBiddingProvinceEnum.HB.getName(), "HB");
        }
        if (spiderConfig.getSpider().getZtb().getBjDailyTask()) {
            start(ContentBiddingProvinceEnum.BJ.getName(), "BJ");
        }
        if (spiderConfig.getSpider().getZtb().getJsDailyTask()) {
            start(ContentBiddingProvinceEnum.JS.getName(), "JS");
        }
        contentBiddingTask.consumer();
    }

    private void start(String province, String name) {
        contentBiddingStatisticsService.sendEmailByProvince(province);
        contentBiddingTask.producer(name);
    }
}
